package com.itheima.demo04;

import java.util.ArrayList;
import java.util.concurrent.*;

/**
 * @author Zhang_Han
 * @version 1.0
 * @date 2020/7/14 19:43
 */
public class Work001 {
    public static void main(String[] args) throws InterruptedException {
        ConcurrentHashMap<String, String> map = new ConcurrentHashMap<>();
        ArrayList<String> list = new ArrayList<>();
        list.add("C:\\Users\\97622\\Desktop\\ROBIN\\day16.md");
        list.add("C:\\Users\\97622\\Desktop\\ROBIN\\day18.md");
        list.add("C:\\Users\\97622\\Desktop\\ROBIN\\day15.md");
        list.add("C:\\Users\\97622\\Desktop\\ROBIN\\day17.md");
        list.add("C:\\Users\\97622\\Desktop\\ROBIN\\day19.md");
        ThreadPoolExecutor tpe = new ThreadPoolExecutor(1,
                3,
                5,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(5),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy());
        //创建CountDownLatch对象
        CountDownLatch countDownLatch = new CountDownLatch(list.size());

        for (int i = 0; i < list.size(); i++) {
            tpe.submit(new MyRunnable(list.get(i), countDownLatch, map));
        }
        //主线程等待其他线程执行完成后再执行;
        countDownLatch.await();
        ConcurrentHashMap.KeySetView<String, String> keys = map.keySet();
        for (String key : keys) {
            String value = map.get(key);
            System.out.println(key+value);
        }
        System.out.println("文件复制完成!");

    }
}
